package cn.design.realize;

/**
 * @author dlq
 * @description
 *     Originator: 原发器。负责创建一个备忘录，用以记录当前对象的内部状态，通过也可以使用它来利用备忘录恢复内部状态。同时原发器还可以根据需要决定Memento存储Originator的那些内部状态
 * @date 2020/10/10 9:59
 * @since 1.0
 */
public class Originator {
    /**
     * 游戏的人物状态
     */
    private String state;
    /**
     * 游戏的人物血量
     */
    private String blood;
    /**
     * 游戏的人物蓝量
     */
    private String blueAmount;

    public Originator(String state, String blood, String blueAmount) {
        this.state = state;
        this.blood = blood;
        this.blueAmount = blueAmount;
    }
    public Originator() {
    }

    /**
     * @description 创建当前状态的备忘录,保存当前游戏进度
     * @param  
     * @return cn.design.realize.Memento
     * @author dlq
     * @date 2020/10/10 10:12
     */
    public Memento createMemento(){
        return new Memento(this.state,this.blood,this.blueAmount);
    }
    /**
     * @description 回滚到之前保存的状态,回滚或载入之前的游戏进度，
     * @param memento
     * @return void
     * @author dlq
     * @date 2020/10/10 10:13
     */
    public void  restoreMemento(Memento memento){
       setState(memento.getState());
       setBlood(memento.getBlood());
       setBlueAmount(memento.getBlueAmount());

    }





    //set get方法
    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getBlood() {
        return blood;
    }

    public void setBlood(String blood) {
        this.blood = blood;
    }

    public String getBlueAmount() {
        return blueAmount;
    }

    public void setBlueAmount(String blueAmount) {
        this.blueAmount = blueAmount;
    }

    @Override
    public String toString() {
        return "Originator{" +
                "state='" + state + '\'' +
                ", blood='" + blood + '\'' +
                ", blueAmount='" + blueAmount + '\'' +
                '}';
    }
}
